home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 3.6 KB | 149 lines | [TEXT/MPS ] |
- // The C++ Booch Components (Version 2.1)
- // (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
- //
- // Restricted Rights Legend
- // Use, duplication, or disclosure is subject to restrictions as set forth
- // in subdivision (c)(1)(ii) of the Rights in Technical Data and Computer
- // Software clause at DFARS 252.227-7013.
- //
- // BCColl.cpp
- //
- // This file contains the definitions for the collection abstract base class
- // and its iterators.
-
- #include "BCColl.h"
-
- template<class Item>
- BC_TCollection<Item>::BC_TCollection() {}
-
- template<class Item>
- BC_TCollection<Item>::BC_TCollection(const BC_TCollection<Item>&) {}
-
- template<class Item>
- BC_TCollection<Item>::~BC_TCollection() {}
-
- template<class Item>
- BC_TCollection<Item>& BC_TCollection<Item>::operator=(const BC_TCollection<Item>& c)
- {
- if (this == &c)
- return *this;
- ((BC_TCollection<Item>&)c).Lock();
- Purge();
- BC_TCollectionActiveIterator<Item> iter(c);
- while (!iter.IsDone()) {
- Add(*iter.CurrentItem());
- iter.Next();
- }
- ((BC_TCollection<Item>&)c).Unlock();
- return *this;
- }
-
- template<class Item>
- BC_Boolean BC_TCollection<Item>::operator==(const BC_TCollection<Item>& c) const
- {
- if (this == &c)
- return 1;
- ((BC_TCollection<Item>&)c).Lock();
- if (Cardinality() != c.Cardinality()) {
- ((BC_TCollection<Item>&)c).Unlock();
- return 0;
- }
- BC_TCollectionActiveIterator<Item> iter_1(*this), iter_2(c);
- while (!iter_1.IsDone()) {
- if (*iter_1.CurrentItem() != *iter_2.CurrentItem()) {
- ((BC_TCollection<Item>&)c).Unlock();
- return 0;
- }
- iter_1.Next();
- iter_2.Next();
- }
- ((BC_TCollection<Item>&)c).Unlock();
- return 1;
- }
-
- template<class Item>
- BC_Boolean BC_TCollection<Item>::operator!=(const BC_TCollection<Item>& c) const
- {
- return !operator==(c);
- }
-
- template<class Item>
- void BC_TCollection<Item>::Lock() {}
-
- template<class Item>
- void BC_TCollection<Item>::Unlock() {}
-
- template<class Item>
- BC_TCollectionActiveIterator<Item>::
- BC_TCollectionActiveIterator(const BC_TCollection<Item>& c)
- : fCollection(c),
- fIndex(c.Cardinality() ? 0 : -1) {}
-
- template<class Item>
- BC_TCollectionActiveIterator<Item>::~BC_TCollectionActiveIterator() {}
-
- template<class Item>
- void BC_TCollectionActiveIterator<Item>::Reset()
- {
- fIndex = fCollection.Cardinality() ? 0 : -1;
- }
-
- template<class Item>
- BC_Boolean BC_TCollectionActiveIterator<Item>::Next()
- {
- fIndex++;
- return !IsDone();
- }
-
- template<class Item>
- BC_Boolean BC_TCollectionActiveIterator<Item>::IsDone() const
- {
- return ((fIndex < 0) || (fIndex >= fCollection.Cardinality()));
- }
-
- template<class Item>
- const Item* BC_TCollectionActiveIterator<Item>::CurrentItem() const
- {
- return IsDone() ? 0 : &fCollection.ItemAt(fIndex);
- }
-
- template<class Item>
- Item* BC_TCollectionActiveIterator<Item>::CurrentItem()
- {
- return IsDone() ? 0 : &((Item&)(fCollection.ItemAt(fIndex)));
- }
-
- template<class Item>
- BC_TCollectionPassiveIterator<Item>::
- BC_TCollectionPassiveIterator(const BC_TCollection<Item>& c)
- : fCollection(c) {}
-
- template<class Item>
- BC_TCollectionPassiveIterator<Item>::~BC_TCollectionPassiveIterator() {}
-
- template<class Item>
- BC_Boolean BC_TCollectionPassiveIterator<Item>::Apply(BC_Boolean (*f)(const Item&))
- {
- BC_TCollectionActiveIterator<Item> iter(fCollection);
- while (!iter.IsDone()) {
- if (!f(*iter.CurrentItem()))
- return 0;
- else
- iter.Next();
- }
- return 1;
- }
-
- template<class Item>
- BC_Boolean BC_TCollectionPassiveIterator<Item>::Apply(BC_Boolean (*f)(Item&))
- {
- BC_TCollectionActiveIterator<Item> iter(fCollection);
- while (!iter.IsDone()) {
- if (!f(*iter.CurrentItem()))
- return 0;
- else
- iter.Next();
- }
- return 1;
- }
-